<template>
  <view class="note">
    <view class="note-title u-flex">
      <view v-if="info.BizType == 21">{{$t('chat.request_friend')}}</view>
      <view v-else-if="info.BizType == 22">{{$t('chat.request_friend_notify')}}</view>
      <view v-else>{{info.Title}}</view>
      <u-tag class="mgl-10" v-if="info.DealType == 2" :text="$t('chat.stat_ignored')" mode="plain" type="info"
             size="mini" />
      <u-tag class="mgl-10" v-if="info.DealType == 1" :text="$t('chat.stat_agreed')" mode="plain" type="success"
             size="mini" />
    </view>
    <view class="note-time">{{info.AddTimeText}}</view>
    <view class="note-txt">
      <text v-if="info.BizType == 21">{{$t('chat.user_iam')}} </text>
      {{info.Content}}
      <text v-if="info.Title == $t('chat.request_friend_notify') && info.DealType == 2"> {{$t('chat.stat_ignored')}}</text>
      <text v-if="info.Title == $t('chat.request_friend_notify') && info.DealType == 1"> {{$t('chat.stat_agreed')}}</text>
    </view>
	
	<view class="attention-item u-flex" v-if="info.BizType == 31" @click="goUser(info.AddAcc)">
		<view class="left u-flex">
			<image :src="info.Avatar == '' ?'../../../static/images/avatar.jpg' :  info.Avatar " class="avatar"></image>
			<view>
				<view class="nickname">{{ info.Nickname}}</view>
				<view class="email">{{ info.Email ? info.Email : info.LoginId}}</view>
			</view>
		</view>
		<view class="right" :class="info.IsFollow == 1 ? '': 'attented'" @click.stop="actFollow(info.AddAcc,info.Nickname)">
			{{info.IsFollow == 1 ? $t('mine.attented'): ('+ ' + $t('mine.attention'))}}
		</view>
	</view>	
	<u-modal v-model="showModal" :show-cancel-button="true" :confirm-text="$t('chat.btn_no_follow')" :cancel-text="$t('chat.btn_cancel')" @confirm="actNoFollow()">
				<view class="slot-content" style="padding: 10rpx 10rpx 10rpx 20rpx;text-align: center">
					<text>{{ $t('mine.confirm_no_follow') }}{{ name }}?</text>
				</view>
			</u-modal>
	<view v-if="info.BizType == 33 || info.BizType == 32 " class="note-btns">
	 <u-button v-if="info.BizType == 33 || info.BizType == 32 " type="primary" @click="goTopic()">{{$t('chat.btn_go_topic')}}
	 </u-button>
	<!-- <view class="nickname">{{info.content}}</view> -->
	</view>
    <view v-if="info.BizType == 21 && info.DealTime == 0" class="note-btns">
      <u-button @click="actRefuse">{{$t('chat.btn_ignore')}}</u-button>
      <u-button type="primary" @click="actAgree">{{$t('chat.btn_agree')}}</u-button>
    </view>


    <view v-if="info.Type == 1" class="note-btns">
      <u-button v-if="info.ExtDataJson.topic != undefined" type="primary" @click="goTopic()">{{$t('chat.btn_go_topic')}}
      </u-button>
      <u-button
          v-if="$store.state.vuex_user.type == 1 && info.BizType != 16 && info.ExtDataJson.Pid != undefined && info.Title !='工程变动确认结果通知' && info.Title !='Workscope Contents Confirmation Result Notice.' && info.Title !='Уведомление о результате подтверждения содержания работ.' &&  info.BizType != 31 &&  info.BizType != 32 &&  info.BizType != 33 &&  info.BizType != 0  "
          type="primary" @click="$goPage('/staff/bench/detail',{project:info.ExtDataJson.Pid,tab:4})">
        {{$t('chat.btn_go_confirm')}}
      </u-button>
	  <u-button
	      v-if="info.BizType == 0 && info.Title == '好友@通知'"
	      type="primary" @click="$goPage('/article/detail',{tid:JSON.parse(info.ExtData).topic})">
	    {{$t('chat.btn_go_check')}}
	  </u-button>
			<u-button
			    v-if="$store.state.vuex_user.type == 1 && info.BizType == 16 && info.ExtDataJson.Pid != undefined"
			    type="primary" @click="$goPage('/staff/bench/detail',{project:info.ExtDataJson.Pid,tab:3})">
			  {{$t('chat.btn_go_project')}}
			</u-button>
			<u-button
			    v-if="$store.state.vuex_user.type == 2 && info.BizType == 16 && info.ExtDataJson.Pid != undefined"
			    type="primary" @click="$goPage('/client/repair/detail',{project:info.ExtDataJson.Pid,tab:2})">
			  {{$t('chat.btn_go_project')}}
			</u-button>
     <u-button
          v-if="$store.state.vuex_user.type == 2 &&info.BizType != 16 && info.BizType != 31   && info.BizType != 32 &&  info.BizType != 33 && info.ExtDataJson.Pid != undefined && info.Title !='工程变动确认结果通知' && info.Title !='Workscope Contents Confirmation Result Notice.' && info.Title !='Уведомление о результате подтверждения содержания работ.' && info.Title !='好友@通知'"
          type="primary" @click="$goPage('/client/repair/detail',{project:info.ExtDataJson.Pid,tab:3})">
        {{$t('chat.btn_go_confirm')}}
      </u-button>
      <u-button v-if="info.ExtDataJson.demand != undefined" type="primary" @click="goDemand()">
        {{$t('chat.btn_go_check')}}
      </u-button>
    </view>
    <view class="detail-repair_content" v-if="list && JSON.parse(JSON.stringify(list)).length > 0">
      <view class="detail-repair_item" v-for="(item, index) in list">
        <view v-if="$store.state.vuex_user.type == 2 && item.Stat==3 " class="note-index"
              @click="$goPage('/repair/edit',{title:'编辑',project:item.Pid,iid:item.Iid,stat:6})">
          <u-tag type="primary" mode="plain" :text="index+1" class="mgr-10" size="mini" />
          <text style="margin-left: 10rpx;">{{item.IndexNo}}</text>
        </view>
        <view v-else-if="$store.state.vuex_user.type == 1 && item.Stat==3 " class="note-index"
              @click="$goPage('/repair/edit',{title:'编辑',project:item.Pid,iid:item.Iid,stat:5})">
          <u-tag type="primary" mode="plain" :text="index+1" class="mgr-10" size="mini" />
          <text style="margin-left: 10rpx;">{{item.IndexNo}}</text>
        </view>
        <view v-else class="note-index">
          <u-tag type="primary" mode="plain" :text="index+1" class="mgr-10" size="mini" />
          <text style="margin-left: 10rpx;">{{item.IndexNo}}</text>
        </view>
        <view class="note-txt u-flex mgb-10">
          <text class="detail-repair_item--child__value  u-flex-1">{{item.ItemName}}</text>
        </view>
        <view class="note-txt">
          <template v-for="(updates,index) in item.UpdateList">
            <view class="mgb-10">{{updates}}<br /></view>
          </template>
        </view>

        <!-- <view class="u-flex mgb-10">
          <view class="detail-repair_item--child__label">{{i18n.submit_data}}：</view>
          <text
            class="detail-repair_item--child__value  u-flex-1">{{item.AddTimeText != '' ? item.AddTimeText : '-'}}</text>
        </view>
        <view class="u-flex mgb-10">
          <view class="detail-repair_item--child__label">{{i18n.submit_person}} ：</view>
          <text
            class="detail-repair_item--child__value  u-flex-1">{{ item.AddAccName != '' ? item.AddAccName : '-'}}</text>
        </view>
        <view class="u-flex">
          <view class="detail-repair_item--child__label">{{i18n.status}}：</view>
          <view class="detail-repair_item--child__value  u-flex-1">
            {{ item.StatText == '' ? '-' : i18n.materials_stat[item.Stat]}}
            <text v-if="item.Stat == 2 && item.DoneTimeText != ''" class="color-gray">
              ({{item.DoneTimeText}})</text>
          </view>
        </view>
        <view class="u-flex mgt-10" v-if="item.Type != ''">
          <view class="detail-repair_item--child__label">{{i18n.spare_type}}：</view>
          <text class="detail-repair_item--child__value  u-flex-1">{{item.Type}}</text>
        </view>
        <view class="u-flex mgt-10" v-if="item.TypeText != ''">
          <view class="detail-repair_item--child__label">{{i18n.spare_name}}：</view>
          <text
            class="detail-repair_item--child__value  u-flex-1">{{item.TypeText}}</text>
        </view>-->
      </view>
      <!-- <u-loadmore :status="status" :icon-type="iconType" :load-text="loadText"
        margin-bottom="45" margin-top="45" color="#C1C0C0" /> -->
    </view>
  </view>
</template>

<script>
import pageMixin from '@/utils/pageMixin';
export default {
  mixins: [pageMixin],
  data() {
    return {
      info: {},
      sid: '',
      list: {},
	  	showModal: false,
    }
  },

  onLoad(opts) {
		console.log('hahaahhhha --------------------------------------')
    this.sid = opts.sid;
    this.getinfo()
  },
  onShow() {},
  components: {},
  computed: {
  },
  methods: {
    getinfo() {
      let that = this;
      that.$http.get('/msg/system/info', {
        sid: that.sid
      }).then(res => {
        that.list = res.list
        let bizType = res.info.BizType;
        let content = res.info.Content;
        if (that.$t('chat.msg_title_'+ bizType) !== undefined) {
          res.info.Title = that.$t('chat.msg_title_'+ bizType);
        }
        if (that.$t('chat.msg_content_.'+ bizType) !== undefined && bizType != 31 && bizType != 16 && bizType != 32 && bizType != 33) {
          //let number = res.Content.replace(/[^0-9]/ig, "");
          let number = (res.info.Content.match(/\d+个工程/g) + "").match(/\d+/g);
          content = that.$t('chat.msg_content_'+ bizType);
          if (uni.getStorageSync('lang')  == '中文') {
            content = content.replace('[projectName]', res.info.ProjectName)
          } else {
            content = content.replace('[projectName]', res.info.ShipName)
          }
          content = content.replace('[userName]', res.info.ExtDataJson.AddAccName || '')
          content = content.replace('[number]', number)
          res.info.Content = content;
        }

        //确认结果状态，2：确认、3：驳回
        let stat = res.info.ExtDataJson.Stat || 0;
        if (stat == 3) {
          let rejectRmk = res.info.ExtDataJson.RejectRmk || '';
          if (rejectRmk != '') {
            content = content.replace('[rejectRmk]', rejectRmk)
            res.info.Content = content;
          }
        } else if (stat == 2) {
          if (that.$t('chat.msg_content_' + bizType +'_confirm')!== undefined) {
            //let number = res.info.Content.replace(/[^0-9]/ig, "");
            let number = (res.info.Content.match(/\d+个工程/g) + "").match(/\d+/g);
            let content = that.$t('chat.msg_content_' + bizType +'_confirm');
            if (uni.getStorageSync('lang') == '中文') {
              content = content.replace('[projectName]', res.info.ProjectName)
            } else {
              content = content.replace('[projectName]', res.info.ShipName)
            }
            content = content.replace('[userName]', res.info.ExtDataJson.AddAccName || '')
            content = content.replace('[number]', number)
            res.info.Content = content;
          }
        }
				//修理单结果通知
				if(bizType == 16) {
					let amount = res.info.Content.slice(res.info.Content.indexOf('为') + 1,res.info.Content.indexOf('详')-1)
					let content = that.$t('chat.msg_content_16');
					console.log(content)
					if (uni.getStorageSync('lang') == '中文') {
					  content = content.replace('[projectName]', res.info.ProjectName)
					} else {
					  content = content.replace('[projectName]', res.info.ShipName)
					}
					content = content.replace('[amount]',amount)
					res.info.Content = content;							
				 }
				 //好友@通知
				if(res.info.Title == '好友@通知'){
					let username =res.info.Content.slice(res.info.Content.indexOf('友')+1,res.info.Content.indexOf('在'))
					console.log(username)
					res.info.Title = that.$t('chat.msg_@_notify');
					let content = that.$t('chat.msg_content_@')
					console.log(content)
					content = content.replace('[userName]', username)
					res.info.Content = content
				}
				//好友关注
				if(bizType == 31) {
					let username = res.info.Content.slice(0,res.info.Content.indexOf('关'))
					let content = that.$t('chat.msg_content_31');
					console.log(content)
					content = content.replace('[userName]',username)
					res.info.Content = content;							
				 }
				if(bizType == 32) {
					 let username = res.info.Content.slice(0,res.info.Content.indexOf('评'))
				 	  let content = that.$t('chat.msg_content_32');
				 		content = content.replace('[userName]',username)
				 		res.info.Content = content;			
				 }
				  //发布文章，所有粉丝发送消息至铃铛
        if(bizType == 33) {
        	 let username = res.info.Content.slice(4,res.info.Content.indexOf('发'))
        	let content = that.$t('chat.msg_content_33');
        	content = content.replace('[userName]',username)
        	res.info.Content = content;		
        }
        that.info = res.info;
        if (that.list) {
          var UpdateList = [];
          for (var item of that.list) {
            if (item.StatText == '待确认') {
              item.StatText = this.$t('project.no_confirmed')
            }
            if (item.StatText == '已确认') {
              item.StatText = this.$t('project.confirmed')
            }
            if (item.StatText == '驳回') {
              item.StatText = this.$t('project.reject')
            }
            if (item.UpdateList) {
              item.UpdateList.forEach(item1 => {
                item1 = item1.replace("编辑工程内容", this.$t('project.edit_project_content'));
                item1 = item1.replace('编辑单位', this.$t('project.edit_unit'));
                item1 = item1.replace('编辑数量', this.$t('project.edit_number'));
                item1 = item1.replace('编辑备注', this.$t('project.edit_remark'));
                item1 = item1.replace('编辑单价', this.$t('project.edit_unit_price'));
                item1 = item1.replace('新增工程内容', this.$t('project.add_project_content'));
                item1 = item1.replace('新增', this.$t('project.btn_add'));
                item1 = item1.replace('删除工程内容', this.$t('project.del_project_content'));
                item1 = item1.replace('删除', this.$t('project.btn_del'));
                item1 = item1.replace('撤回删除工程内容', this.$t('project.recall_del_project_content'));
                item1 = item1.replace('撤回删除', this.$t('project.recall_del'));
                UpdateList.push(item1)
              })
              item.UpdateList = UpdateList;
              UpdateList = []
            }
          }
        }
		console.log(this.info)
      })
    },
    goTopic() {
      var tid = this.info.ExtDataJson.topic;
	    if(this.info.BizType == 32 ||this.info.BizType == 33 ){
		    tid = this.info.AddAcc;
	    }
	  
      //判断帖子是否已删除
      this.$http.get('/bbs/topic/isdel', {
        tid: tid
      }).then(res => {
        if (res == 1) {
          this.$u.route('/pages/article/detail/index', {
            tid: tid
          });
        }
      })
    },
    goDemand() {
      this.$u.route('/pages/demand/detail/index', {
        dkey: this.info.ExtDataJson.demand
      });
    },
    actAgree() {
      let data = {
        sid: this.sid,
        deal_type: 1,
      };
      this.$http.post('/msg/system/deal', data).then(res => {
        uni.showToast({
          title: '同意成功'
        });
        this.getinfo();
      });
    },
    actRefuse() {
      let data = {
        sid: this.sid,
        deal_type: 2,
      };
      this.$http.post('/msg/system/deal', data).then(res => {
        uni.showToast({
          title: '忽略成功'
        });
        this.getinfo();
      });
    },
	actFollow(uid,name) {
		if(this.info.IsFollow == 1) {
			this.uid = uid;
			// this.index = index
			this.showModal = true
			this.name = name
		}else{
			this.info.IsFollow = 1
			this.$u.toast(this.$t('mine.attention_success'))
			this.$http.post('/client/user/account/follow',{otherUid: uid}).then(res=>{
				//this.getList()
			})
		
		}			
	},
	actNoFollow() {
			this.$http.post('/client/user/account/follow',{otherUid: this.uid}).then(res=>{
			    this.info.IsFollow = -1
			})
	},
	goUser(e) {
    				let uid = e.currentTarget.dataset.uid;
    				if (uid > 1) {
    					uni.navigateTo({
    						url: '/pages/user/index?uid=' + uid
    					});
    				}
    			},
  }
}
</script>

<style lang="scss" scoped>
.mgl-10 {
  margin-left: 10rpx;
}

.note {
  white-space: normal;
  word-break: break-all;
  padding: 60rpx 30rpx;

  &-title {
    font-size: 30rpx;
    color: #131313;
    margin-bottom: 30rpx;
  }

  &-time {
    font-size: 24rpx;
    color: #999999;
    margin-bottom: 40rpx;
  }

  &-txt {
    text-indent: 44rpx;
    font-size: 28rpx;
    color: #666666;
    line-height: 44rpx;
  }

  &-index {
    margin-left: 32rpx;
  }

  &-btns {
    position: fixed;
    width: 100%;
    bottom: 0;
    left: 0;
    text-align: center;

    .u-btn {
      display: inline-block;
      margin: 30rpx;
    }
  }
  .attention-item {
  	justify-content: space-between;
  	align-items: center;
  	padding: 32rpx 0;
  	border-bottom: 1px solid #e6e4e7;
  	.avatar {
  		width: 90rpx;
  		height: 90rpx;
  		border-radius: 90rpx;
  		margin-right: 20rpx;
  	}
  	.nickname {
  		width: 200rpx;
  		overflow: hidden;
  		text-overflow:ellipsis;
  		white-space:nowrap;
  		font-size: 30rpx;
  	}
  	.email {
  		width: 200rpx;
  		overflow: hidden;
  		text-overflow:ellipsis;
  		white-space:nowrap;
  		font-size: 26rpx;
  		color: #7a7c7c;
  	}
  	.right {
  	  padding: 12rpx 50rpx;
  		white-space: nowrap;
  		background-color: #F4F4F4;
  		color: #7a7c7c;
  		border-radius: 30rpx;
  		font-size:28rpx;
  		margin-top:-8rpx;
  	}
  	.attented {
  		background-color: #E8EEFE ;
  		color: #1651EF ;
  	}
  }
}
</style>
